package org.koon.jadelyre;

import org.jadelyre.core.Channel;
import org.jadelyre.core.Handler;
import org.jadelyre.core.ende.Packet;
import org.koon.Dispatcher;
import org.koon.KooRequest;
import org.koon.MoonResponse;

public class KoonHandler implements Handler {
    private Dispatcher dispatcher;

    public KoonHandler(Dispatcher dispatcher) {
        this.dispatcher = dispatcher;
    }

    @Override
    public void handle(Packet packet, Channel channel) {
        KooRequest httpRequest = (KooRequest)packet;
        MoonResponse httpResponse = new MoonResponse();
        httpResponse.setBody("hello world".getBytes());
        dispatcher.dispatch(httpRequest,httpResponse);
        channel.getSendTask().addTask(httpResponse).execute();
    }
}
